<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class Event_c extends CI_Controller {
        function __construct() {
            parent::__construct();
            $this->load->model(array('event_m','coordinator_m','client_m',
                'supplier_m', 'checklist_m', 'task_m'));
        }
        
        function index() {
            $data['content'] = 'pages/events/events';
            $data['title'] = 'Events';
            $data['current_page'] = 'events-page';
            $data['class'] = '';
            $data['back_to'] = 'dashboard';
            $this->load->view('includes/template', $data);
        }
        
        function calendar_view($year = null, $month = null){
            $data['content'] = 'pages/events/events_calendar_view';
            $data['title'] = 'Events Calendar View';
            $data['current_page'] = 'events-calendar-page';
            $data['class'] = '';
            $data['back_to'] = 'events';
            $data['calendar'] = $this->event_m->generate_calendar($year, $month);
            $this->load->view('includes/template', $data);
        }
        
        function list_view(){
            $data['content'] = 'pages/events/events_list_view';
            $data['title'] = 'Events List View';
            $data['current_page'] = 'events-list-page';
            $data['class'] = '';
            $data['back_to'] = 'events';
            $this->load->view('includes/template', $data);
            
        }
        
        function event_detail() {
            $data['content'] = 'pages/events/event_details';
            $data['title'] = 'Event Detail';
            $data['current_page'] = 'event-create-page';
            $data['class'] = '';
            $data['back_to'] = 'events';
            //$data['event_type'] = $this->event_m->get_event_types();
            //$data['event_venues'] = $this->event_m->get_venues();
            //$data['coor'] = $this->coordinator_m->get_employees($this->session->userdata('accid'));
            //$data['clients'] = $this->client_m->get_clients();
            $this->load->view('includes/template', $data);
        }
        
        function event_supplier($msg = '') {
            $data['content'] = 'pages/events/event_supplier';
            $data['title'] = 'Event Supplier';
            $data['current_page'] = 'event-supplier-page';
            $data['class'] = '';
            $data['back_to'] = 'events';
            $data['supplier'] = $this->supplier_m->get_all_supplier();
            $data['msg'] = $msg;
            $this->load->view('includes/template', $data);
        }
        
        function event_checklist() {
            $data['content'] = 'pages/events/event_checklist';
            $data['title'] = 'Event Checklist';
            $data['current_page'] = 'event-checklist-page';
            $data['class'] = '';
            $data['back_to'] = 'events';
            $data['category'] = $this->checklist_m->get_all_category();
            $this->load->view('includes/template', $data);
        }
        
        function event_task($msg = null) {
            $data['content'] = 'pages/events/event_task';
            $data['title'] = 'Event Task/s';
            $data['current_page'] = 'event-task-page';
            $data['class'] = '';
            $data['back_to'] = 'events';
            $data['msg'] = $msg;
            $this->load->view('includes/template', $data);
        }
        
        function event_task_ajax() {
            echo json_encode($this->task_m->get_all_tasks());
        }
        
        function save_event_task() {
            $desc = $this->input->post('task-desc');
            $date = $this->input->post('task-date');
            $time = $this->input->post('task-time');
            $coor = $this->session->userdata('accid');
            $action = $this->input->post('action');
            if($action === 'insert') {
                $data = array(
                    'task_description' => $desc,
                    'task_date' => $date,
                    'task_time' => $time,
                    'coordinator_id'=> $coor
                );
                $this->task_m->insert_task($data);
                $this->event_task('<p class="success">Task successfully saved.</p>');
            }elseif($action === 'update') {
                $data = array(
                    'task_description' => $desc,
                    'task_date' => $date,
                    'task_time' => $time,
                    'coordinator_id'=> $coor
                );
                $this->task_m->update_task($this->input->post('task-id'), $data);
                $this->event_task('<p class="success">Task successfully updated.</p>');
            }
        }
    }
